package com.homedo.odin.solution.enumcode.user;

import java.util.Arrays;
import lombok.Getter;

@Getter
public enum BizCodeEnum {
    /*积分类型 1：签到 2：上传方案并通过审核 3：点赞 4：发表评论 5：邀请用户注册 6：发布悬赏*/
    SIGN_IN(1, "签到"),
    UPLOAD_SOLUTION_AUDIT_SUCCESS(2, "上传方案并通过审核"),
    LIKE(3, "点赞"),
    COMMENT(4, "发表评论"),
    INVITATION_USER_REGISTER(5, "邀请用户注册"),
    PUBLISH_BOUNTY(6, "发布悬赏");

    private Integer dbValue;
    private String displayValue;

    BizCodeEnum(Integer roleCode, String displayValue) {
        this.dbValue = roleCode;
        this.displayValue = displayValue;
    }

    /**
     * 判断是否存在枚举dbValue
     */
    public static boolean dbValueExist(Integer dbValue) {
        return Arrays.stream(BizCodeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
    }

    /**
     * 判断是否存在枚举displayValue
     */
    public static boolean displayValueExist(String displayValue) {
        return Arrays.stream(BizCodeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
    }

    /**
     * 匹配获取对应的DisplayValue
     */
    public static String getExistDisplayValue(Integer dbValue) {
        return Arrays.stream(BizCodeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
                .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
    }
}
